<?php
	
	$conexion = new mysqli('localhost','root','10495270','datos_sensor');
	
	$categorias = array('nombre');
	$sensor1 = array('mota1');
	$sensor2 = array('mota2');
	
	$consulta = "SELECT DISTINCT(nombre) FROM red_sensores WHERE nombre = 'sensor_1' OR nombre = 'sensor_2' ORDER BY nombre";
	$result = $conexion->query($consulta);
	
	while ($fila = $result->fetch_array()) {
		$categorias[] = $fila['nombre'];
	}
	
	$consulta = "SELECT nombre, mota1, mota2 FROM red_sensores;";
	$result = $conexion->query($consulta);
	while($fila = $result->fetch_array())
	{				
			if ( $fila['nombre'] == 'sensor_1')
			{
				$sensor1[] = (double) $fila['mota1'];
				$sensor1[] = (double) $fila['mota2'];
			}
			elseif ( $fila['nombre'] == 'sensor_2')
			{
				$sensor2[] = (double) $fila['mota1'];
				$sensor2[] = (double) $fila['mota2'];
			}	
			
	}
	//print_r($sensor1);
	echo json_encode( array($categorias, $sensor1, $sensor2) );
	
?>
